<?php
/**
 * @version 	$Id: fApplication.class.php 82 2010-03-17 08:45:39Z mylifeisskidrow@gmail.com $
 * @author 		$Author: mylifeisskidrow@gmail.com $
 * @copyright 	Copyright (c) 2010 Luu Trong Hieu. All right reserved.
 * @license 	GNU/GPL see license.php
 */

defined('IN_FLYWHEEL') or die('Restricted Access!');
/**
 * Base application
 * 	Application nen tang cua he thong.
 * 
 * @package 	system
 * @subpackage 	application
 */
abstract class fApplication {
	const 
		ENV_DEV = 'dev',
		ENV_TEST = 'test',
		ENV_PROD = 'prod';
	/**
	 * Application name
	 *
	 * @var string
	 */	
	protected $name;
	
	/**
	 * Get Application
	 * 
	 * @return string name of application
	 */
	public function getName() {
		return $this->name;
	}
	
	/**
	 * Create Web Application
	 *
	 * @param string $name
	 * @param string $environment
	 * @param boolean $debug
	 * @return instance of App
	 */
	public static function createWebApplication ($name, $environment, $debug = false) {
		if ($debug) {			
			fProfiler::getInstance()->mark('Create web application', 'system.'.get_class($this));		
		}
		$app = fFactory::createApplication($name, $environment, $debug, 'web');		
		$app->_init();		
		return $app;
	}
	
	protected function _init() {}
	
	/**
	 * Create Console Application
	 *
	 * @param string $name
	 * @param string $environment
	 * @param boolean $debug
	 */
	public static function createConsoleApplication($name, $environment, $debug = false) {		
	}
	
	/**
	 * End application
	 *
	 * @param string | int $message
	 */
	public static function end($message = 0) {
		exit($message);		
	}
	
	/**
	 * Run
	 * 	run application
	 * 
	 * @abstract 
	 */
	abstract public function run();
}